home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / ghview15.gz / ghostview-1.5.tar / ghostview-1.5 / dialogs.c < prev    next >
C/C++ Source or Header  |  1993-07-23  |  6KB  |  196 lines

  1. /*
  2.  * dialogs.c -- Dialog box for ghostview.
  3.  * Copyright (C) 1992  Timothy O. Theisen
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *   Author: Tim Theisen           Systems Programmer
  20.  * Internet: tim@cs.wisc.edu       Department of Computer Sciences
  21.  *     UUCP: uwvax!tim             University of Wisconsin-Madison
  22.  *    Phone: (608)262-0438         1210 West Dayton Street
  23.  *      FAX: (608)262-9777         Madison, WI   53706
  24.  */
  25.  
  26. #include <X11/Intrinsic.h>
  27. #include <X11/StringDefs.h>
  28. #include <X11/Xos.h>
  29. #include <X11/Xaw/Cardinals.h>
  30. #include <X11/Xaw/Form.h>
  31. #include <X11/Xaw/Label.h>
  32. #include <X11/Xaw/AsciiText.h>
  33. #include <X11/Xaw/Command.h>
  34. #include "gv.h"
  35.  
  36. static String okay_accelerators =
  37.     "#override\n\
  38.      <Key>Return: set() notify() unset()\n";
  39.  
  40. /* Create a dialog widget */
  41. /* It is just a form widget with
  42.  *   a label prompt
  43.  *   a text response
  44.  *   an oky button
  45.  *   a cancel button */
  46. Widget
  47. CreateDialog(parent, name, okay_callback, cancel_callback)
  48.     Widget parent;
  49.     String name;
  50.     XtCallbackProc okay_callback;
  51.     XtCallbackProc cancel_callback;
  52. {
  53.     Widget form, prompt, response, okay, cancel;
  54.     Arg args[20];
  55.     Cardinal num_args;
  56.  
  57.     form = XtCreateManagedWidget(name, formWidgetClass, parent, NULL, ZERO);
  58.  
  59.                             num_args = 0;
  60.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  61.     XtSetArg(args[num_args], XtNbottom, XtChainTop);    num_args++;
  62.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  63.     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
  64.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  65.     XtSetArg(args[num_args], XtNborderWidth, 0);    num_args++;
  66.     prompt = XtCreateManagedWidget("prompt", labelWidgetClass,
  67.                    form, args, num_args);
  68.  
  69.                             num_args = 0;
  70.     XtSetArg(args[num_args], XtNfromVert, prompt);    num_args++;
  71.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  72.     XtSetArg(args[num_args], XtNbottom, XtChainTop);    num_args++;
  73.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  74.     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
  75.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  76.     XtSetArg(args[num_args], XtNeditType, XawtextEdit);    num_args++;
  77.     XtSetArg(args[num_args], XtNresize, XawtextResizeWidth);    num_args++;
  78.     XtSetArg(args[num_args], XtNstring, "");        num_args++;
  79.     response = XtCreateManagedWidget("response", asciiTextWidgetClass,
  80.                      form, args, num_args);
  81.  
  82.                             num_args = 0;
  83.     XtSetArg(args[num_args], XtNfromVert, response);    num_args++;
  84.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  85.     XtSetArg(args[num_args], XtNbottom, XtChainTop);    num_args++;
  86.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  87.     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
  88.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  89.     XtSetArg(args[num_args], XtNaccelerators,
  90.          XtParseAcceleratorTable(okay_accelerators));    num_args++;
  91.     okay = XtCreateManagedWidget("okay", commandWidgetClass,
  92.                  form, args, num_args);
  93.     XtAddCallback(okay, XtNcallback, okay_callback, form);
  94.  
  95.                             num_args = 0;
  96.     XtSetArg(args[num_args], XtNfromVert, response);    num_args++;
  97.     XtSetArg(args[num_args], XtNfromHoriz, okay);    num_args++;
  98.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  99.     XtSetArg(args[num_args], XtNbottom, XtChainTop);    num_args++;
  100.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  101.     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
  102.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  103.     cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
  104.                    form, args, num_args);
  105.     XtAddCallback(cancel, XtNcallback, cancel_callback, parent);
  106.  
  107.     XtInstallAccelerators(response, okay);
  108.     XtSetKeyboardFocus(form, response);
  109.  
  110.     return form;
  111. }
  112.  
  113. /* get the prompt from the dialog box.  Used a startup time to
  114.  * save away the initial prompt */
  115. String
  116. GetDialogPrompt(w)
  117.     Widget w;
  118. {
  119.     Arg args[1];
  120.     Widget label;
  121.     String s;
  122.  
  123.     label = XtNameToWidget(w, "prompt");
  124.     XtSetArg(args[0], XtNlabel, &s);
  125.     XtGetValues(label, args, ONE);
  126.     return XtNewString(s);
  127. }
  128.  
  129. /* set the prompt.  This is used to put error information in the prompt */
  130. void
  131. SetDialogPrompt(w, newprompt)
  132.     Widget w;
  133.     String newprompt;
  134. {
  135.     Arg args[1];
  136.     Widget label;
  137.  
  138.     label = XtNameToWidget(w, "prompt");
  139.     XtSetArg(args[0], XtNlabel, newprompt);
  140.     XtSetValues(label, args, ONE);
  141. }
  142.  
  143. /* get what the user typed */
  144. String
  145. GetDialogResponse(w)
  146.     Widget w;
  147. {
  148.     Arg args[1];
  149.     Widget response;
  150.     String s;
  151.  
  152.     response = XtNameToWidget(w, "response");
  153.     XtSetArg(args[0], XtNstring, &s);
  154.     XtGetValues(response, args, ONE);
  155.     return XtNewString(s);
  156. }
  157.  
  158. /* set the default reponse */
  159. void
  160. SetDialogResponse(w, s)
  161.     Widget w;
  162.     String s;
  163. {
  164.     Arg args[3];
  165.     Widget response;
  166.     XFontStruct *font;
  167.     Dimension width, leftMargin, rightMargin;
  168.  
  169.     response = XtNameToWidget(w, "response");
  170.     XtSetArg(args[0], XtNfont, &font);
  171.     XtSetArg(args[1], XtNleftMargin, &leftMargin);
  172.     XtSetArg(args[2], XtNrightMargin, &rightMargin);
  173.     XtGetValues(response, args, THREE);
  174.     width = font->max_bounds.width * strlen(s) + leftMargin + rightMargin;
  175.  
  176.     XtSetArg(args[0], XtNstring, s);
  177.     XtSetArg(args[1], XtNwidth, width);
  178.     XtSetValues(response, args, TWO);
  179.     XawTextSetInsertionPoint(response, strlen(s));
  180.  
  181. }
  182.  
  183. /* clear the response */
  184. void
  185. ClearDialogResponse(w)
  186.     Widget w;
  187. {
  188.     Arg args[2];
  189.     Widget response;
  190.  
  191.     response = XtNameToWidget(w, "response");
  192.     XtSetArg(args[0], XtNstring, "");
  193.     XtSetArg(args[1], XtNwidth, 100);
  194.     XtSetValues(response, args, TWO);
  195. }
  196.